
package com.sfdlJPush.utils;

import android.app.Activity;
import android.content.Context;
import android.os.Bundle;
import android.support.v4.app.FragmentActivity;
import android.view.View;
import android.widget.ProgressBar;
import android.widget.TextView;

import cn.jpush.android.api.JPushInterface;

import com.sfdlJPush.controller.B5MAppManager;

public abstract class B5MBaseActivity extends FragmentActivity
{
    protected String mTrackActivity = ""; // GA 统计
    public Context mContext;
    public Activity mActivity;
    public TextView tv_title;
    public ProgressBar mProgressBar;

    @Override
    protected void onCreate(Bundle savedInstanceState)
    {
        // TODO Auto-generated method stub
        super.onCreate(savedInstanceState);
        doBefore(savedInstanceState);
        View containerView = getLayoutInflater().inflate(doGetContentViewId(), null);
        setContentView(containerView);
        init();
        doInitSubViews(containerView);
        doInitDataes();
        doAfter();
        //
        // 添加Activity到堆栈
        B5MAppManager.getInstance().addActivity(this);
    }

    private void init()
    {
        // TODO Auto-generated method stub
        mActivity = this;
        mContext = this;
    }

    /**
     * 标题栏左边view点击事件处理,默认是finish
     */
    protected void onHeadLeftViewClicked()
    {
        // TODO Auto-generated method stub
        finish();
    }

    public abstract int doGetContentViewId();

    public abstract void doInitSubViews(View containerView);

    public abstract void doInitDataes();

    public abstract void doAfter();

    protected void doBefore(Bundle savedInstanceState)
    {
        // TODO Auto-generated method stub
    }

    @Override
    protected void onDestroy()
    {
        super.onDestroy();
        // 结束Activity&从堆栈中移除
        B5MAppManager.getInstance().finishActivity(this);
    }

    /**
     * 显示头部网络加载进度圈
     */
    public void showHeadProgressBar()
    {
        mProgressBar.setVisibility(View.VISIBLE);
    }

    /**
     * 隐藏头部网络加载进度圈
     */
    public void hideHeadProgressBar()
    {
        mProgressBar.setVisibility(View.GONE);
    }

    @Override
    protected void onResume()
    {
        // TODO Auto-generated method stub
        super.onResume();
        JPushInterface.onResume(this);
    }

    @Override
    protected void onPause()
    {
        // TODO Auto-generated method stub
        super.onPause();
        JPushInterface.onPause(this);
    }
}
